home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-15 / ns_16550.zip / COMTEST.C < prev    next >
Text File  |  1991-07-20  |  7KB  |  249 lines

  1. /* comtest.c
  2.  
  3.  written : 1/30/89 by  Louis Shay
  4.  modified: Welson Lin, Greg Dejager
  5.  
  6.  National Semiconductor Corporation
  7.  PC Peripherals Business Center Application Group
  8.  
  9.   This program will test the functions of any type of UART that is found in
  10.   the IBM PC, AT, or compatible machines at standard port addresses.
  11.   The program will prompt the user to select the port address, COM1 - COM8.
  12.   The program will attempt to identify what type of UART is present at the
  13.   selected address. Once the port type is determined, the program will test
  14.   the appropriate device functions. The test is completely self-contained,
  15.   and makes use of the internal loop-back diagnostic feature of the UART.
  16.   The program accesses the following modules:
  17.  
  18.   int port_id() - this function returns a value for port type.
  19.   0, port_id unsuccessful
  20.   1, type = INS8250, INS8250-B
  21.   2, type = INS8250A, NS16450
  22.   3, type = NS16550A
  23.   4, type = NS16C552
  24.  
  25.   int rwt8250() - tests register read/write functions of the 8250 type device.
  26.  
  27.   int rwt450() - tests read/write functions of the 8250A, 16450, or 16550A.
  28.  
  29.   int i450() - internal loopback diagnostic for all types.
  30.  
  31.   int ififo() - tests FIFO-mode functions of the NS16550A type UART.
  32.  
  33.   int 552afr() - tests 16C552 Alternate Function Register Concurrent Writes
  34.  
  35. */
  36.  
  37. #include <stdio.h>
  38. #include <conio.h>
  39. #include <stdlib.h>
  40. #include "ns16550a.h"
  41.  
  42. #define SERIAL_1  0x03f8
  43. #define SERIAL_2  0x02f8
  44. #define SERIAL_3  0x3220
  45. #define SERIAL_4  0x3228
  46. #define SERIAL_5  0x4220
  47. #define SERIAL_6  0x4228
  48. #define SERIAL_7  0x5220
  49. #define SERIAL_8  0x5228
  50. #define TYPE0 "Port ID check failed. "
  51. #define TYPE1 "INS8250 or INS8250-B"
  52. #define TYPE2 "INS8250A or NS16450"
  53. #define TYPE3 "NS16550A"
  54. #define TYPE4 "NS16C552"
  55.  
  56. /* function prototypes */
  57. int far port_id(void), rwt8250(void), rwt450(void), i450(void), ififo(void), afr552(void);
  58. void delay(void);
  59.  
  60. /* globals */
  61. int ubase, ubase2, *uart, fatal_error = 0;
  62. char line[100];
  63. char *response;
  64.  
  65.  
  66. main()
  67. {
  68.   int count, rddata, again, confirm();  /* function to get (Y)es or (N)o from 
  69.                                         user */
  70.   char *uart_type;
  71.   int errors = 0, port_number, type_number;
  72.  
  73.   /* print banner message */
  74.   printf("\nNational Semiconductor Corporation\n");
  75.   printf("UART self diagnostic program for the IBM PS/2 and compatibles.\n");
  76.  
  77.  
  78. START:                          /* restart point */
  79.  
  80.   fatal_error = 0;              /* reset error flag */
  81.   errors = 0;
  82.   printf("\nSelect Port:\n");
  83.   printf("\t1. SERIAL_1 (03f8-03ff)\n\t2. SERIAL_2 (02f8-02ff)\n");
  84.   printf("\t3. SERIAL_3 (3220-3227)\n\t4. SERIAL_4 (3228-322f)\n");
  85.   printf("\t5. SERIAL_5 (4220-4227)\n\t6. SERIAL_6 (4228-422f)\n");
  86.   printf("\t7. SERIAL_7 (5220-5227)\n\t8. SERIAL_8 (5228-522f)\n");
  87.   while( 1 ) {
  88.     printf("\nEnter number ( 1 - 8 ): ");
  89.     scanf( "%d", &port_number );
  90.     if(( port_number >= 1 ) && ( port_number <= 8 ))
  91.       break;
  92.     (void)gets(line);           /* clear buffer */
  93.   }
  94.   switch( port_number ) {
  95. case 1: ubase = SERIAL_1;       break;
  96. case 2: ubase = SERIAL_2;       break;
  97. case 3: ubase = SERIAL_3;       break;
  98. case 4: ubase = SERIAL_4;       break;
  99. case 5: ubase = SERIAL_5;       break;
  100. case 6: ubase = SERIAL_6;       break;
  101. case 7: ubase = SERIAL_7;       break;
  102. case 8: ubase = SERIAL_8;       break;
  103.   }
  104.  
  105.  
  106. /* determine port type & action taken */
  107.  
  108.   printf("\n -- SERIAL_%d selected.\n", port_number );
  109.   type_number = port_id();              /* call id function */
  110.  
  111. WHICH:
  112.   switch( type_number ) {
  113.     case 0:
  114.       printf("%s", TYPE0 );
  115.       if( confirm() == 0 )
  116. goto END;
  117.       while( 1 ) {      /* continue - get port type from user */
  118. printf("\nSelect port type:\n");
  119. printf("\t(1) %s\n\t(2) %s\n\t(3) %s\n\t(4) %s\n", TYPE1, TYPE2, TYPE3, TYPE4 );
  120. printf("\nEnter number: ");
  121. scanf("%d", &type_number );
  122. if( ( type_number > 0 ) && ( type_number < 5 ))
  123.   goto WHICH;
  124. (void)gets(line);               /* clear buffer */
  125.       }
  126.     case 1:
  127.       printf("\nDevice type is: %s\n", TYPE1 );
  128.       goto TEST_1;
  129.     case 2:
  130.       printf("\nDevice type is: %s\n", TYPE2 );
  131.       goto TEST_2;
  132.     case 3:
  133.       printf("\nDevice type is: %s\n", TYPE3 );
  134.       goto TEST_2;
  135.     case 4:
  136.       printf("\nDevice type is: %s\n",TYPE4 );
  137.       goto TEST_3;
  138.   }
  139.  
  140. TEST_1:         /* test 8250 functions */
  141.  
  142.   errors = 0;
  143.   errors = rwt8250();           /* 8250 register read/write test */
  144.   if( fatal_error )             /* potentially fatal r/w errors at this point */
  145.   {
  146.     printf(" -- Potentially fatal read/write errors found. ");
  147.     if( confirm() == 0 )
  148.       goto END;
  149.   }
  150.   /* continue testing */
  151.   fatal_error = 0;              /* reset fatal_error flag */
  152.   errors += i450();             /* character-mode diagnostic test */
  153.   goto END;
  154.  
  155.  
  156. TEST_2:         /* test 16450 functions */
  157.  
  158.   errors = 0;
  159.   errors = rwt450();            /* 16450/16550A register read/write test */
  160.   if( fatal_error )             /* read/write errors found */
  161.   {
  162.     printf(" -- Potentially fatal read/write errors found. ");
  163.     if( confirm() == 0 )
  164.       goto END;
  165.   }
  166.   /* continue testing */
  167.   fatal_error = 0;
  168.   errors += i450();             /* character-mode diagnostic test */
  169.   if( type_number == 3 )
  170.   {
  171.     if( fatal_error )
  172.       goto END;
  173.     errors += ififo();          /* FIFO-mode test (16550A only) */
  174.   }
  175. goto END;
  176.  
  177. TEST_3:
  178.   errors = 0;
  179.   errors = rwt450();            /* 16450/16550A register read/write test */
  180.   if( fatal_error )            /* read/write errors found */
  181.   {
  182.     printf(" -- Potentially fatal read/write errors found. ");
  183.     if( confirm() == 0 )
  184.       goto END;
  185.   }
  186.   /* continue testing */
  187.   fatal_error = 0;
  188.   errors += i450();             /* character-mode diagnostic test */
  189.   if( fatal_error )
  190.   {
  191.     printf(" -- Potentially fatal data loopback errors found. ");
  192.     if( confirm() == 0 )
  193.       goto END;
  194.   }
  195.   /*continue testing*/
  196.   fatal_error = 0;
  197.   errors += ififo();            /* FIFO-mode test  */
  198.   if( fatal_error )             /* FIFO errors found */
  199.     {
  200.     printf(" -- Potentially fatal FIFO errors found. ");
  201.     if( confirm() == 0 )
  202.       goto END;
  203.     }
  204.     /*continue testing*/
  205.     errors += afr552();         /* 16C552 Alternate Function Reg test */
  206.  
  207.  
  208. END:            /* prints total errors and restarts/quits */
  209.   printf("\nTotal errors found = %d\n", errors );
  210.   printf("Test complete. ");
  211.  CHECK:
  212.   again = confirm();
  213.   switch ( again) {
  214.    case 0 :
  215.     break;
  216.    case 1 :
  217.     goto START;
  218.    case 2 :
  219.      printf("\n");
  220.      goto CHECK;
  221.    }
  222. }       /* end of main()  */
  223.  
  224. int confirm()
  225.   int yes_or_no;
  226.   /* this function asks the user "Continue? (y/n):", and returns a '1' if
  227.   the response is yes and '0' if the response is not yes */
  228.   printf("Continue? (y/n):");
  229.   yes_or_no = getche();
  230.   switch ( yes_or_no ) {
  231.   case 0x59 :
  232.     return( 1 );
  233.   case 0x79 :
  234.     return( 1 );
  235.   case 0x4e :
  236.     return( 0 );
  237.   case 0x6e :
  238.     return( 0 );
  239.   case 0x0d :
  240.     return (1);
  241.   default :
  242.     return (2);
  243.   }
  244. }
  245.  
  246.  
  247.  
  248.